<?php
namespace app\mini\model;

use think\Model;
use app\mini\model\Order as Orders;
use traits\model\SoftDelete;

class Member extends Model
{

    protected $autoWriteTimestamp = true;

    use SoftDelete;

    protected $deleteTime = 'delete_time';

    /*
     * 查询用户信息
     * @param $where where
     * @param $field field
     * @author cpy(1442435897@qq.com)
     */
    public function getUserInfo($where,$field = '*') {
        $res = $this->field($field)->where($where)->find();
        return empty($res)?array():$res->toArray();
    }

    /*
     * 查询所有信息
     * @param $where where
     * @param $field field
     * @author cpy(1442435897@qq.com)
     */
    public function selectAllInfo($where,$field = '*') {
        $res = $this->field($field)->where($where)->order('id desc')->select();
        return empty($res)?array():$res->toArray();
    }

    /*
     * 查询所有信息
     * @param $where where
     * @param $field field
     * @author cpy(1442435897@qq.com)
     */
    public function selectInfo($where,$limit,$field = '*') {
        $res = $this->field($field)->where($where)->limit($limit)->order('id desc')->select();
        return empty($res)?array():$res->toArray();
    }


    /**
     * 查询会员是否符合vip条件
     * @param $member_id
     * @author hey_heyang(635870453@qq.com)
     * @return array
     */
    public function checkMemberVip($member_id){
        $orModel = new Orders();
        $res1 = $orModel->where(['project_id'=>['in',[46,50]],'status'=>['gt',1],'type'=>1,'uid'=>$member_id])->sum('money'); //被光  46,50   30000
        $res2 = $orModel->where(['project_id'=>['in',[51,53]],'status'=>['gt',1],'type'=>1,'uid'=>$member_id])->sum('money');  //封神  51,53   10000
        $res3 = $orModel->where(['project_id'=>['in',[37,44]],'status'=>['gt',1],'type'=>1,'uid'=>$member_id])->sum('money'); //科幻  37,44   10000
        if(($res1>=30000) || ($res2>=10000) || ($res3>=10000)){
            $res=1;   // vip
        }else{
            $res=2;   //非vip
        }
        return $res;
    }


}